package com.secondkill.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by zhangkai12 on 2018/7/9.
 */
@Configuration
public class RabbitMqConfig {

    public static final String MIAOSHA_QUEUE = "miaosha.queue";
    public static final String TOPICQUEUE1 = "topic.queue1";
    public static final String TOPICQUEUE2 = "topic.queue2";
    public static final String TOPICEXCHANGE = "TOPIC_EXCHANGE";
    public static final String FANOUTEXCHANGE = "FANOUT_EXCHANGE";


    @Bean
    public Queue createMiaoshaQueue() {
        return new Queue(MIAOSHA_QUEUE);
    }
    @Bean
    public Queue createQueue() {
        return new Queue("hello_topic");
    }

    @Bean
    public Queue createSomeQueueTopic() {
        return new Queue("someQueue");
    }

    @Bean
    public Queue createQueueTopic1() {
        return new Queue(TOPICQUEUE1);
    }
    @Bean
    public Queue createQueueTopic2() {
        return new Queue(TOPICQUEUE2);
    }
    @Bean
    public TopicExchange createTopicExchange() {
        return new TopicExchange(TOPICEXCHANGE);
    }

    @Bean
    public FanoutExchange createFanoutExchange() {

        return new FanoutExchange(FANOUTEXCHANGE);
    }
    @Bean
    public Binding bindTopic1ToTopicExchange() {
        return BindingBuilder.bind(createQueueTopic1()).to(createTopicExchange()).with("topic.routingkey1");
    }


    @Bean
    public Binding bindTopic2ToTopicExchange() {
        return BindingBuilder.bind(createQueueTopic2()).to(createTopicExchange()).with("topic.#");
    }

    /**
     * 广播
     * @return
     */
    @Bean
    public Binding bindFanoutExchange() {
        return BindingBuilder.bind(createQueueTopic2()).to(createFanoutExchange());
    }
}
